package com.nhatviet.webservice.activities.flickr;

import com.nhatviet.webservice.AppMain;
import com.nhatviet.webservice.R;
import com.nhatviet.webservice.helpers.ListItemAdapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

public class FlickrResultsActivity extends Activity
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.flickr_result);

		TextView noResultTextView = (TextView) findViewById(R.id.text_no_result);

		if (AppMain.xmlParserHandlerList.get(0).getPhotosList() == null
				|| AppMain.xmlParserHandlerList.get(0).getPhotosList().size() == 0)
		{
			noResultTextView.setText(getString(R.string.no_result));
		}
		else
		{
			noResultTextView.setText("");
			ListView listView = (ListView) findViewById(R.id.list_result);
			//listView.setAdapter(new ListItemAdapter(this, AppMain.xmlParserHandlerList.get(0).getPhotosListAttribute(XMLParserHandler.XML_START_PHOTO_ATTRIBUTE_ID)));
			listView.setAdapter(new ListItemAdapter(this, AppMain.xmlParserHandlerList.get(0).getPhotosList()));
			listView.setTextFilterEnabled(true);
			listView.setOnItemClickListener(new OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position, long id)
				{
					AppMain.currentFlickrPhoto = AppMain.xmlParserHandlerList.get(0).getPhotosList().get(position);
					Intent intent = new Intent(FlickrResultsActivity.this, FlickrItemDetailActivity.class);
					startActivity(intent);
				}
			});
		}
	}
}
